﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.BLL;
using CMS.Entity;

public partial class news_msn_BussinessProfileList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string stock = string.IsNullOrEmpty(Request["stock"]) ? "000001" : Request["stock"];
            DateTime endDate = string.IsNullOrEmpty(Request["enddate"]) ? DateTime.Parse("2011-01-01") : DateTime.Parse(Request["enddate"]);
            YearProfileBLL bll = new YearProfileBLL();
            var c = bll.GetOne(stock, endDate);
            string content = c.Content.Replace(" ", "&nbsp;").Replace(" ", "&nbsp;&nbsp;").Replace("\r\n", "<br/>");
            Localize1.Text = content;
            lblStock.Text = stock;
            BussinessProfileListBLL bussinessProfileListBLL = new BussinessProfileListBLL();
            var lst= bussinessProfileListBLL.GetLst(stock, endDate);
            repeater1.DataSource = lst;
            repeater1.DataBind();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                long id = long.Parse(Request["id"]);
            
                var temp = bussinessProfileListBLL.GetOne(id);
                txtTitle.Text = temp.Item;
                txtContent.Text = temp.Content;
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string stock = Request["stock"];
        DateTime endDate = DateTime.Parse(Request["enddate"]);
        BussinessProfileListBLL bll = new BussinessProfileListBLL();
        if (string.IsNullOrEmpty(Request["id"]))
        {
            //添加
            BussinessProfileList entity = new BussinessProfileList();
            entity.EndDate = endDate;
            entity.Item = txtTitle.Text;
            entity.Content = txtContent.Text;
            entity.RecTime = DateTime.Now;
            entity.Stock = stock;
            bll.Add(entity);
        }
        else
        {
            //更新
            long id = long.Parse(Request["id"]);
            var c = bll.GetOne(id);
            c.Id = id;
            c.Item = txtTitle.Text;
            c.Content = txtContent.Text;
            c.ModTime = DateTime.Now;
            bll.Update(c);
        }
        Response.Redirect("BussinessProfileList.aspx?stock=" + stock + "&enddate=" + endDate.ToString("yyyy-MM-dd"));
    }
    protected void btnSetOver_Click(object sender, EventArgs e)
    {
        string stock = Request["stock"];
        DateTime endDate = DateTime.Parse(Request["enddate"]);
        YearProfileBLL bll = new YearProfileBLL();
        var c = bll.GetOne(stock, endDate);
        c.ModTime = DateTime.Now;
        c.BussinessProfileListFlag = true;
        bll.Update(c);
        ClientScript.RegisterStartupScript(GetType(), "aa", "alert('设置成功');document.location='Default.aspx'", true);
    }
}